/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO.Apoiar;

import DAO.Usuario.HibernateUtil;
import Model.Apoiar;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.hibernate.Session;

/**
 *
 * @author pedro
 */
@Path("/apoiar")
public class ApoiarDao {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public Response cadastroUsuario(Apoiar apoiar) {
        Session session = null;
        String response;
        try{
        session=HibernateUtil.getSession();
        HibernateUtil.beginTransaction();
        session.save(apoiar);
        HibernateUtil.commitTransaction();
        response="OK";
        }
        catch(Exception e){
            System.out.println(e);
            response="Error";
            session.getTransaction().rollback();
        }
        finally {
            try {
                HibernateUtil.closeSession();
            } catch (Throwable e) {
                System.out.println(e.getMessage());
            }
        }
        
        return Response.status(201).entity(response).build();
    }
}
